<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/css/swiper.css">
  <style>
    .swiper-slide{
      height: 300px;
      background-color: rgb(147, 153, 96);
    }
    .swiper-slide:nth-child(2n){
      height: 300px;
      background-color: rgb(118, 84, 172);
    }
  </style>
</head>
<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/4.0.2/js/swiper.js"></script>
  <script>
    const Home = {
      template: `
        <div>
          <h2>home组件</h2>
          <button @click="addLi">增加li</button>  
          <hr/>
          <div class="swiper-container">
            <div class="swiper-wrapper">
              <div class="swiper-slide" v-for="banner in arr" :key="banner">
                {{ banner }}
              </div>
            </div>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
          </div>
        </div>
      `,
      data(){
        return {
          msg: '你好世界',
          arr: [1,2,3,4],
          swiper: null
        }
      },
      methods: {
        initSwiper(){
          // 初始化轮播
          this.swiper = new Swiper('.swiper-container', {
            autoplay: true,//可选选项，自动滑动
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev',
            }
          })
        },
        addLi(){
          this.arr.push(this.arr.length+1);
        }
      },
      
      mounted(){
        console.log('template已经编译完成--mounted');
        this.initSwiper();
      },
     
      updated(){
        this.initSwiper();
      }
    }
    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>